﻿using UnityEngine;

public class UserPrefsMgr
{
    public static string clientVersion;
    public static string systemSoftware;
    public static string systemHardware;
    public static string telComOper;
    public static string network;
    public static int screenHeight;
    public static int screenWidth;
    public static int memory;
    public static float density;
    public static string cpuHardware;
    public static string glRender;
    public static string glVersion;
    public static string deviceId;

    #region 

    private static string LastUserKey
    {
        get
        {
            string roleStr = GetKeyValueString(GlobalString.keyLastRoleID);
            if (string.IsNullOrEmpty(roleStr))
            {
                return roleStr;
            }
            return roleStr + "_";
        }
    }

    public static int GetInt(string key)
    {
        return GetKeyValueInt(LastUserKey + key);
    }

    public static void SetInt(string key, int value)
    {
        SetKeyValueInt(LastUserKey + key, value);
    }

    public static float GetFloat(string key)
    {
        return GetKeyValueFloat(LastUserKey + key);
    }

    public static void SetFloat(string key, float value)
    {
        SetKeyValueFloat(LastUserKey + key, value);
    }

    public static string GetString(string key)
    {
        return GetKeyValueString(LastUserKey + key);
    }

    public static void SetString(string key, string value)
    {
        SetKeyValueString(LastUserKey + key, value);
    }

    #endregion
    
    public static int GetKeyValueInt(string key)
    {
        return PlayerPrefs.GetInt(key, 0);
    }

    public static void SetKeyValueInt(string key, int value)
    {
        PlayerPrefs.SetInt(key, value);
        PlayerPrefs.Save();
    }

    public static float GetKeyValueFloat(string key)
    {
        return PlayerPrefs.GetFloat(key, 0);
    }

    public static void SetKeyValueFloat(string key, float value)
    {
        PlayerPrefs.SetFloat(key, value);
        PlayerPrefs.Save();
    }

    public static string GetKeyValueString(string key)
    {
        return PlayerPrefs.GetString(key, "");
    }
    
    public static void SetKeyValueString(string key, string value)
    {
        PlayerPrefs.SetString(key, value);
        PlayerPrefs.Save();
    }
}